package com.hxzy.common.service.impl;

import com.hxzy.common.service.BaseService;
import com.hxzy.mapper.MyBatisBaseDao;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;

/**
 * @author nick
 */
@Transactional
public class BaseServiceImpl<Model, PK extends Serializable>  implements BaseService<Model,PK> {

    private MyBatisBaseDao myBatisBaseDao;

    public void setMyBatisBaseDao(MyBatisBaseDao myBatisBaseDao) {
        this.myBatisBaseDao = myBatisBaseDao;
    }


    @Override
    public boolean deleteByPrimaryKey(PK id) {
        int count=this.myBatisBaseDao.deleteByPrimaryKey(id);
        return  count>0;
    }

    @Override
    public boolean insert(Model record) {
        return this.myBatisBaseDao.insert(record)>0;
    }


    @Override
    public boolean insertSelective(Model record) {
        return this.myBatisBaseDao.insertSelective(record)>0;
    }


    @Override
    public Model selectByPrimaryKey(PK id) {
        return (Model) this.myBatisBaseDao.selectByPrimaryKey(id);
    }


    @Override
    public boolean updateByPrimaryKeySelective(Model record) {
        return this.myBatisBaseDao.updateByPrimaryKeySelective(record)>0;
    }


    @Override
    public boolean updateByPrimaryKey(Model record) {
        return this.myBatisBaseDao.updateByPrimaryKey(record)>0;
    }
}
